//
//  NSString+SYSHA_1.m
//  GBMD5
//
//  Created by dllo on 16/8/16.
//  Copyright © 2016年 郭宝. All rights reserved.
//

#import "NSString+SYSHA_1.h"
#import <CommonCrypto/CommonCrypto.h>
@implementation NSString (SYSHA_1)
- (NSString *)stringWithSYSHA_1
{
//    将字符串转成c字符串
    const char *cString = [self UTF8String];
//    求长度
    CC_LONG len = (CC_LONG)strlen(cString);
    unsigned char bytes[CC_MD5_DIGEST_LENGTH];
//    SHA1转换
    CC_SHA1(cString, len, bytes);
    NSMutableString *finalSHA1 = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH];
    for (int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) {
        [finalSHA1 appendFormat:@"%02x",bytes[i]];
    }
    return finalSHA1;
}
@end
